package com.example.wangyongdong.bearsqlitedemo.spadd;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;

import com.example.wangyongdong.bearsqlitedemo.entity.BrandEntity;

import java.util.List;

/**
 * Created by wangyongdong on 2017/4/27.
 */

public class SpAddAdapter extends BaseAdapter{
    private BrandEntity brandEntity;
    private Context context;
    private List<Integer> index;
    private List<String> name;

    public SpAddAdapter(Context context) {
        this.context = context;
    }

    public void setBrandEntity(BrandEntity brandEntity) {
        index = brandEntity.getIdxes();
        name = brandEntity.getNames();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (index == null){
            return 0;
        }
        return index.size();
    }

    @Override
    public Object getItem(int position) {
        return name.get(position);
    }

    @Override
    public long getItemId(int position) {
        return index.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(android.R.layout.simple_spinner_item,parent,false);
        }
        TextView textView = (TextView) convertView;
        textView.setText(name.get(position));
        return convertView;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(android.R.layout.simple_spinner_dropdown_item,parent,false);
        CheckedTextView textView = (CheckedTextView) convertView;
        textView.setText(name.get(position));
        return convertView;

    }
}
